# -*- coding:utf-8 -*- 
"""
url 和 cookie
"""
import urllib;
import urllib2;
import cookielib;

if(__name__=="__main__"):
    
    '相当于 Request'
    'request = urllib2.Request("http://www.google.com.hk");'
    
    '相当于 Response'
    'response = urllib2.urlopen(request);'
    
    """
    request = urllib2.Request("http://www.google.com/images/logo_sm.gif");
    
    response = urllib2.urlopen(request);
    
    m_file = open("/home/kelly/log.gif","wb");
    
    m_file.write(response.read());
    """
    
    '携带 cookie'
    
    cc = cookielib.LWPCookieJar(); '定义 Cookie'
    
    opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cc));
    
    #opener.addheaders = [('User-Agent','Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20100101 Firefox/14.0.1')];
    
    '安装 cookie'
    urllib2.install_opener(opener);
    
    request = urllib2.Request("http://www.baidu.com");
    
    response = urllib2.urlopen(request);
    
    print cc;
    
    #print response.read();